class CorsMiddleware {
    constructor() {
        this.middleware = this.middleware.bind(this);
    }

    middleware(req, res, next) {
        res.setHeader('Access-Control-Allow-Origin', '*');
        res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
        res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
        res.setHeader('Access-Control-Allow-Credentials', 'true');
        if (req.method === 'OPTIONS') {
            res.status(200).end();
            return;
        }
        next();
    }
}

module.exports = CorsMiddleware;